package com.gzdh.dishrecognition.ui.view;

import static android.content.Context.MODE_PRIVATE;
import static com.dhkj.web.utils.DataUtils.type;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.icu.math.BigDecimal;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dhkj.web.bean.MacMainpSbruanDinner;
import com.dhkj.web.utils.MyObserverRes;
import com.dhkj.web.utils.MyObserverUZip;
import com.dhkj.web.utils.RequestUtils;
import com.gzdh.dishrecognition.MainActivity;
import com.greendao.dao.BmcmEntityDao;
import com.greendao.dao.BmzlEntityDao;
import com.greendao.dao.FkEntityDao;
import com.greendao.dao.MacMainpFoodMenuEntityDao;
import com.greendao.dao.MacMainpSbruanDinnerEntityDao;
import com.greendao.dao.WeekMenuBakEntityDao;
import com.gzdh.dishrecognition.AppContext;
import com.gzdh.dishrecognition.R;
import com.gzdh.dishrecognition.config.ProductConst;
import com.gzdh.dishrecognition.config.SysConstConfig;
import com.gzdh.dishrecognition.entity.BmcmEntity;
import com.gzdh.dishrecognition.entity.BmzlEntity;
import com.gzdh.dishrecognition.entity.FkEntity;
import com.gzdh.dishrecognition.entity.MacMainpFoodMenuEntity;
import com.gzdh.dishrecognition.entity.MacMainpSbruanDinnerEntity;
import com.gzdh.dishrecognition.entity.WeekMenuBakEntity;
import com.gzdh.dishrecognition.event.CartEvent;
import com.gzdh.dishrecognition.event.RefEvent;
import com.gzdh.dishrecognition.model.ProductCartModel;
import com.gzdh.dishrecognition.model.WeekMenuBakModel;
import com.gzdh.dishrecognition.ui.activity.ScanTakeFoodActivity;
import com.gzdh.dishrecognition.ui.activity.SelectPayActivity;
import com.gzdh.dishrecognition.ui.adapter.LeftBmcmAdapter;
import com.gzdh.dishrecognition.ui.adapter.defaultview.BmzlHorizontalAdapter;
import com.gzdh.dishrecognition.ui.adapter.defaultview.DefaultCartAdapter;
import com.gzdh.dishrecognition.ui.adapter.defaultview.FoodsAdapter;

import com.gzdh.dishrecognition.ui.dialog.MsgDialog;
import com.gzdh.dishrecognition.ui.dialog.ShowFoodsCardDialog;
import com.gzdh.dishrecognition.ui.pre.CardInfoPre;

import com.gzdh.dishrecognition.util.ProductSUtils;
import com.gzdh.dishrecognition.util.SystemUtils;

import net.posprinter.posprinterface.TaskCallback;

import org.greenrobot.eventbus.EventBus;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

public class DefaultModelView extends LinearLayout {

    private final Cache<String,String> cache = CacheBuilder.newBuilder().maximumSize(1000).
            expireAfterWrite(3, TimeUnit.SECONDS).build();
    private Context mContext;
    private RecyclerView bmcmRv;
    private RecyclerView productRv;
    private RecyclerView cartRv;
    private HorizontalListView zlRv;
    private TextView netStatusRv;
    private TextView payBut;
    private TextView cancelBut;
    private TextView amountTv;
    private TextView refBut;
    private ImageView printBtn;
    private ImageView scanTakeBtn;
    private MacMainpSbruanDinnerEntityDao macMainpSbruanDinnerEntityDao;

    private BmcmEntityDao bmcmEntityDao;
    private BmzlEntityDao bmzlEntityDao;
    private FkEntityDao fkEntityDao;
    private WeekMenuBakEntityDao weekMenuBakEntityDao;
    private MacMainpFoodMenuEntityDao macMainpFoodMenuEntityDao;
    private BmzlHorizontalAdapter bmzlHorizontalAdapter;
    private FoodsAdapter foodsAdapter;
    private DefaultCartAdapter defaultCartAdapter;

    private BleNfcClick bleNfcClick;

    private CardInfoPre cardInfoPre;

    private MsgDialog msgDialog;

    private Thread closeDialogThread;

    private long lastCard;

    private List<MacMainpFoodMenuEntity> macMainpFoodMenuEntities = new ArrayList<>();

    public void setBleNfcClick(BleNfcClick bleNfcClick) {
        this.bleNfcClick = bleNfcClick;
    }

    public interface BleNfcClick {
        void onUserClick();
    }

    private LeftBmcmAdapter leftBmcmAdapter;

    public void setCardInfoPre(CardInfoPre cardInfoPre) {
        this.cardInfoPre = cardInfoPre;
    }

    public DefaultModelView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.view_mode_default, this, true);
        mContext = context;
        msgDialog = new MsgDialog(mContext);
        fkEntityDao = AppContext.getInstance().getDaoSession().getFkEntityDao();
        initView();
        initDate();

        foodsAdapter = new FoodsAdapter(mContext);
        bmzlHorizontalAdapter = new BmzlHorizontalAdapter(mContext);
        if (SysConstConfig.getInstance().isHideDinner()) {
            bmcmRv.setVisibility(GONE);
        }

        leftBmcmAdapter = new LeftBmcmAdapter(mContext);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        bmcmRv.setLayoutManager(layoutManager);
        bmcmRv.setAdapter(leftBmcmAdapter);

        List<MacMainpSbruanDinnerEntity> macMainpSbruanDinnerEntityList = macMainpSbruanDinnerEntityDao.loadAll();
        ProductSUtils.setSbruanDinnerName(macMainpSbruanDinnerEntityList);

        leftBmcmAdapter.setList(macMainpSbruanDinnerEntityList);
//        leftBmcmAdapter.notifyDataSetChanged();
        leftBmcmAdapter.setUserOnClick(this::selectBmcm);


        GridLayoutManager productLayoutManager = new GridLayoutManager(mContext, SysConstConfig.getInstance().getFoodsMenuRow());
        productLayoutManager.setOrientation(RecyclerView.VERTICAL);
        productRv.setLayoutManager(productLayoutManager);
        productRv.setAdapter(foodsAdapter);
        productRv.addItemDecoration(new MyGridSpacingItemDecoration(3));

        foodsAdapter.setOnClick(product -> {
            if (!SysConstConfig.getInstance().isKuacan() &&
                    ProductConst.getInstance().getProductCartModelList().size() > 0) {
                ProductCartModel productCartModel = ProductConst.getInstance().getProductCartModelList().get(0);
                if (!productCartModel.getDinner().equals(product.getDinner())) {
                    Toast.makeText(mContext, "当前系统设置不允许跨餐次订餐", Toast.LENGTH_LONG).show();
                    return;
                }
            }
            ProductConst.getInstance().addProductCart(product);
            EventBus.getDefault().post(new CartEvent());
        });

        defaultCartAdapter = new DefaultCartAdapter(mContext);
        LinearLayoutManager layoutManager2 = new LinearLayoutManager(mContext);
        cartRv.setLayoutManager(layoutManager2);
        cartRv.setAdapter(defaultCartAdapter);

        refBut = findViewById(R.id.refBut);

        refBut.setOnClickListener(view -> {
            //刷新按钮
            ProgressDialog dialog = new ProgressDialog(mContext);
            dialog.setMessage("正在检卡");
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
            SharedPreferences systemI = mContext.getSharedPreferences("systemI", MODE_PRIVATE);
            String user = systemI.getString("user", "");
            RequestUtils.getBaseSysInfo(mContext, user, SystemUtils.getSerialNumber(),

                    new MyObserverUZip<JSONObject>(mContext, type(JSONObject.class), false) {
                        @Override
                        public void onSuccess(JSONObject result) {
                            System.out.println(result.toJSONString());
                            List<BmcmEntity> bmcmEntityList = result.getJSONArray("bmcm").toJavaList(BmcmEntity.class);
                            bmcmEntityDao.deleteAll();
                            bmcmEntityDao.insertInTx(bmcmEntityList);


                            JSONArray bmzlJsonArray = result.getJSONArray("bmzl");

                            List<BmzlEntity> bmzlEntityList = new ArrayList<>();
                            for (int i = 0; i < bmzlJsonArray.size(); i++) {
                                BmzlEntity bmzlEntity = new BmzlEntity();
                                bmzlEntity.setBm(bmzlJsonArray.getJSONObject(i).getString("bm").trim());
                                bmzlEntity.setName(bmzlJsonArray.getJSONObject(i).getString("name"));
                                bmzlEntityList.add(bmzlEntity);
                            }
                            bmzlEntityDao.deleteAll();
                            bmzlEntityDao.insertInTx(bmzlEntityList);

                            try {
                                List<WeekMenuBakEntity> weekMenuBakEntityList = result.getJSONArray("weekMenuBak").toJavaList(WeekMenuBakEntity.class);
                                if (weekMenuBakEntityList.size() > 0) {
                                    weekMenuBakEntityDao.deleteAll();
                                    weekMenuBakEntityDao.insertInTx(weekMenuBakEntityList);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            try {

                                List<MacMainpSbruanDinner> macMainpSbruanDinnerList = result.getJSONArray("macMainpSbruanDinnerList")
                                        .toJavaList(MacMainpSbruanDinner.class);
                                macMainpSbruanDinnerEntityDao.deleteAll();
                                if (macMainpSbruanDinnerList.size() > 0) {
                                    List<MacMainpSbruanDinnerEntity> macMainpSbruanDinnerEntities = new ArrayList<>();
                                    for (MacMainpSbruanDinner goo : macMainpSbruanDinnerList) {
                                        MacMainpSbruanDinnerEntity macMainpSbruanDinnerEntity = new MacMainpSbruanDinnerEntity();
                                        macMainpSbruanDinnerEntity.setDinner(goo.getDinner());
                                        macMainpSbruanDinnerEntity.setStartTime(goo.getStartTime());
                                        macMainpSbruanDinnerEntity.setEndTime(goo.getEndTime());
                                        macMainpSbruanDinnerEntity.setDeviceId(goo.getDeviceId());
                                        macMainpSbruanDinnerEntity.setId(goo.getId());
                                        macMainpSbruanDinnerEntities.add(macMainpSbruanDinnerEntity);
                                    }
                                    macMainpSbruanDinnerEntityDao.insertInTx(macMainpSbruanDinnerEntities);
                                }
                                loadFoodsMenu();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            try {

                                List<MacMainpFoodMenuEntity> macMainpFoodMenuList = result.getJSONArray("macMainpFoodMenuList")
                                        .toJavaList(MacMainpFoodMenuEntity.class);
                                macMainpFoodMenuEntityDao.deleteAll();
                                if (macMainpFoodMenuList.size() > 0) {
                                    List<MacMainpFoodMenuEntity> macMainpFoodMenuEntities = new ArrayList<>();
                                    for (MacMainpFoodMenuEntity goo : macMainpFoodMenuList) {
                                        MacMainpFoodMenuEntity macMainpFoodMenuEntity = new MacMainpFoodMenuEntity();
                                        macMainpFoodMenuEntity.setId(goo.getId());
                                        macMainpFoodMenuEntity.setName(goo.getName());
                                        macMainpFoodMenuEntity.setPrice(goo.getPrice());
                                        macMainpFoodMenuEntity.setCardid(goo.getCardid());
                                        macMainpFoodMenuEntity.setCode(goo.getCode());
                                        macMainpFoodMenuEntity.setZl(goo.getZl());
                                        macMainpFoodMenuEntities.add(macMainpFoodMenuEntity);
                                    }
                                    macMainpFoodMenuEntityDao.insertInTx(macMainpFoodMenuEntities);
                                }

                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            ProductConst.getInstance().setProductCartModelList(new ArrayList<>());
                            EventBus.getDefault().post(new CartEvent());

                        }

                        @Override
                        public void onFailure(Throwable e, String errorMsg) {

                        }
                    });
            dialog.dismiss();
        });

        //扫码领餐
        scanTakeBtn = findViewById(R.id.scanTakeBtn);
        if(!SysConstConfig.getInstance().isScanTake()) {
            scanTakeBtn.setVisibility(View.GONE);
        }
        scanTakeBtn.setOnClickListener(view -> {
            if(cache.getIfPresent("scanTake") != null) {
                return;
            }
            cache.put("scanTake", String.valueOf(System.currentTimeMillis()));
            ScanTakeFoodActivity.start(mContext);
        });

        printBtn = findViewById(R.id.printBtn);
        printBtn.setOnClickListener(view -> {
            UsbManager usbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
            HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
            for (UsbDevice device : deviceList.values()) {
                // 得到此设备的一个接口
                if (device.getInterface(0).getInterfaceClass() == 7) {
                    MainActivity.myBinder.ConnectUsbPort(mContext, device.getDeviceName(), new TaskCallback() {
                        @Override
                        public void OnSucceed() {
                            MainActivity.ISCONNECT = true;
                            Toast.makeText(mContext, "打印机连接成功", Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        public void OnFailed() {
                            MainActivity.ISCONNECT = false;
                            Toast.makeText(context,"连接异常",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }
        });

        findViewById(R.id.bluetoothBut).setOnClickListener(view -> {
            if (bleNfcClick != null) {
                bleNfcClick.onUserClick();
            }
        });
    }

    private void initView() {
        bmcmRv = findViewById(R.id.bmcmRv);
        zlRv = findViewById(R.id.zlRv);
        netStatusRv = findViewById(R.id.netStatusRv);
        netStatusRv.setOnClickListener(v -> {

        });
        productRv = findViewById(R.id.productRv);
        cartRv = findViewById(R.id.cartRv);
        cancelBut = findViewById(R.id.cancelBut);
        payBut = findViewById(R.id.payBut);
        amountTv = findViewById(R.id.amountTv);

        cancelBut.setOnClickListener(view -> {
            ProductConst.getInstance().setProductCartModelList(new ArrayList<>());
            EventBus.getDefault().post(new CartEvent());
        });

        payBut.setOnClickListener(view -> {
            if(new BigDecimal(ProductConst.getInstance().getProductCartPrice()).compareTo(new BigDecimal(0)) <= 0) {
                Toast.makeText(mContext,"请确认支付金额", Toast.LENGTH_SHORT).show();
                return;
            }
            String cacheValue = cache.getIfPresent("isSubmit");
            if(cacheValue != null) {
                return;
            }
            cache.put("isSubmit", String.valueOf(System.currentTimeMillis()));
            SelectPayActivity.startAct(mContext);
        });
        closeDialog();
    }

    public void confirmClick() {
        if(cache.getIfPresent("confirm") != null) {
            return;
        }
        cache.put("confirm", System.currentTimeMillis() + "");
        payBut.performClick();
    }

    public void cancelClick() {
        if(defaultCartAdapter != null) {
            defaultCartAdapter.subFinalLine();
        }
    }

    public void getCardInfo(String cardSn) {
        if (System.currentTimeMillis() - lastCard <= (5 * 1000)) {
            return;
        }
        lastCard = System.currentTimeMillis();
        closeDialogThread.interrupt();
        if (SysConstConfig.getInstance().isOnLinePay()) {
            FkEntity fkEntity = fkEntityDao.queryBuilder().where(FkEntityDao.Properties.Cardsn.eq(cardSn.toUpperCase())).unique();
            if (fkEntity == null) {
                showMsgDialog("查无此人", 30);
                return;
            }
            if (fkEntity.getIsGuaShi() == 1) {
                showMsgDialog("此卡已挂失", 30);
                return;
            }
            if(fkEntity.getValiddate().compareTo(new Date()) < 0) {
                showMsgDialog("此卡已超过有效期", 30);
                return;
            }
            String cardId = fkEntity.getCardId();
            String kye = fkEntity.getKye();
            String btYe = fkEntity.getBtye();
            showMsgDialog(String.format("工号：%s\r\n卡余额：%s\r\n补贴余额：%s", cardId, kye, btYe), 24);
        } else {
            RequestUtils.getFk(mContext, SystemUtils.getSerialNumber(), cardSn, new MyObserverRes<>(mContext, false) {
                @Override
                public void onSuccess(JSONObject result) {
                    if (result == null) {
                        showMsgDialog("查无此人", 30);
                        return;
                    }
                    String cardId = result.getString("cardId");
                    String kye = result.getString("kye");
                    String btYe = result.getString("btye");
                    showMsgDialog(String.format("工号：%s\r\n卡余额：%s\r\n补贴余额：%s", cardId, kye, btYe), 24);
                }

                @Override
                public void onFailure(Throwable e, String errorMsg) {
                    if(e != null && e.getCause() != null) {
                        if(e.getCause().toString().contains("java.net.ConnectException")) {
                            errorMsg = "网络异常,请切换离线状态读卡";
                        }
                    }
                    Log.e("DefaultModelView", errorMsg, e);
                    showMsgDialog(errorMsg, 24);
                }
            });
        }
    }

    private void showMsgDialog(String text, Integer textSize) {
        if(msgDialog.isShowing()) {
            msgDialog.dismiss();
        }
        msgDialog.show();
        TextView msg = msgDialog.getMsgTv();
        msg.setText(text);
        msg.setTextSize(textSize);
        if(cardInfoPre != null) {
            cardInfoPre.setMsgText(text);
            EventBus.getDefault().post(new RefEvent());
            closeDialog();
            closeDialogThread.start();
        }
    }

    private void closeDialog() {
        closeDialogThread = new Thread(() -> {
            try {
                Thread.sleep(5000);
                if(cardInfoPre != null) {
                    Activity activity = (Activity) mContext;
                    activity.runOnUiThread(() -> {
                        cardInfoPre.hide();
                        msgDialog.dismiss();
                    });
                }
            } catch (InterruptedException e) {
                Log.e("readCardThread: ", e.toString());
            }
        });
    }

    private void initDate() {
        bmcmEntityDao = AppContext.getInstance().getDaoSession().getBmcmEntityDao();
        bmzlEntityDao = AppContext.getInstance().getDaoSession().getBmzlEntityDao();
        weekMenuBakEntityDao = AppContext.getInstance().getDaoSession().getWeekMenuBakEntityDao();
        macMainpFoodMenuEntityDao = AppContext.getInstance().getDaoSession().getMacMainpFoodMenuEntityDao();
        macMainpSbruanDinnerEntityDao = AppContext.getInstance().getDaoSession().getMacMainpSbruanDinnerEntityDao();
        loadFoodsMenu();
    }


    public void loadFoodsMenu() {
        macMainpFoodMenuEntities = macMainpFoodMenuEntityDao.loadAll();
    }

    @SuppressLint("Range")
    public void selectBmcm(MacMainpSbruanDinnerEntity bmcmEntity) {
        //餐次点击传入
        foodsAdapter.setDatas(new ArrayList<>());
        String yDay = new SimpleDateFormat("MM-dd").format(new Date());
        List<WeekMenuBakModel> weekMenuBakModelList = new ArrayList<>();
        Cursor c = AppContext.getInstance().getDaoSession().getDatabase().rawQuery(" select * from BMZL_ENTITY where bm in( " +
                "select zl from WEEK_MENU_BAK_ENTITY where Yday=? and dinner=? group by zl)", new String[]{yDay, bmcmEntity.getDinner()});
        while (c.moveToNext()) {
            WeekMenuBakModel weekMenuBakModel = new WeekMenuBakModel();
            weekMenuBakModel.setYday(yDay);
            weekMenuBakModel.setBm(c.getString(c.getColumnIndex("bm")).trim());
            weekMenuBakModel.setBmcm(bmcmEntity.getDinner());
            weekMenuBakModel.setName(c.getString(c.getColumnIndex("name")).trim());
            weekMenuBakModelList.add(weekMenuBakModel);
        }
        c.close();
        zlRv.setAdapter(bmzlHorizontalAdapter);
        if (weekMenuBakModelList.size() > 0) {
            WeekMenuBakModel weekMenuBakModel = weekMenuBakModelList.get(0);
            showProduct(weekMenuBakModel);
            bmzlHorizontalAdapter.setSelect(0);
        }
        bmzlHorizontalAdapter.setList(weekMenuBakModelList);
        zlRv.setOnItemClickListener((adapterView, view, positionI, id) -> {
            WeekMenuBakModel weekMenuBakModel = weekMenuBakModelList.get(positionI);
            showProduct(weekMenuBakModel);
            bmzlHorizontalAdapter.setSelect(positionI);
        });
    }


    public void showProduct(WeekMenuBakModel weekMenuBakModel) {
        List<WeekMenuBakEntity> weekMenuBakEntityList = weekMenuBakEntityDao.queryBuilder()
                .where(WeekMenuBakEntityDao.Properties.Dinner.eq(weekMenuBakModel.getBmcm()))
                .where(WeekMenuBakEntityDao.Properties.Zl.eq(weekMenuBakModel.getBm()))
                .where(WeekMenuBakEntityDao.Properties.Yday.eq(weekMenuBakModel.getYday())).list();
        List<WeekMenuBakModel.Product> productList = new ArrayList<>();
        for (WeekMenuBakEntity goo : weekMenuBakEntityList) {
            WeekMenuBakModel.Product product = new WeekMenuBakModel.Product();
            product.setBm(goo.getBm());
            product.setName(goo.getName());
            product.setPrice(goo.getPrice());
            product.setZl(goo.getZl());
            product.setDinner(goo.getDinner());
            product.setAddr(goo.getAddr());
            productList.add(product);

        }
        foodsAdapter.setDatas(productList);
    }

    public void resShow() {
        defaultCartAdapter.notifyDataSetChanged();
        foodsAdapter.notifyDataSetChanged();
        bmzlHorizontalAdapter.notifyDataSetChanged();
        amountTv.setText("￥" + ProductConst.getInstance().getProductCartPrice());
        if(!SysConstConfig.getInstance().isScanTake()) {
            scanTakeBtn.setVisibility(View.GONE);
        } else {
            scanTakeBtn.setVisibility(View.VISIBLE);
        }
    }

    public void scanQr(String code) {

    }

    public void foodCard(int card) {
        MacMainpFoodMenuEntity macMainpFoodMenuEntity = macMainpFoodMenuEntities.stream().filter(macMainpFoodMenuEntity1 -> String.valueOf(card).equals(macMainpFoodMenuEntity1.getCardid()))
                .findFirst().orElse(null);
        if (macMainpFoodMenuEntity == null) {
            Toast.makeText(mContext, "菜卡有误请核对", Toast.LENGTH_SHORT).show();
            return;
        }

        ProductCartModel mProductCartModel = new ProductCartModel();
        MacMainpSbruanDinnerEntity dinnerEntity = leftBmcmAdapter.getDinner();
        if (dinnerEntity != null) {
            mProductCartModel.setDinner(dinnerEntity.getDinner());
        } else {
            mProductCartModel.setDinner("");
        }
        mProductCartModel.setNumber(1);
        mProductCartModel.setName(macMainpFoodMenuEntity.getName());
        mProductCartModel.setZl(macMainpFoodMenuEntity.getZl());
        mProductCartModel.setPrice(macMainpFoodMenuEntity.getPrice());
        mProductCartModel.setBm(macMainpFoodMenuEntity.getCode());
        ProductConst.getInstance().addProductCart(mProductCartModel);
        EventBus.getDefault().post(new CartEvent());
        ShowFoodsCardDialog showFoodsCardDialog = new ShowFoodsCardDialog(mContext);
        showFoodsCardDialog.show();
        showFoodsCardDialog.getNameTv().setText(macMainpFoodMenuEntity.getName());
        showFoodsCardDialog.getPriceTv().setText(macMainpFoodMenuEntity.getPrice());

    }

    public void connectedNet() {
        netStatusRv.setText("已联网");
        netStatusRv.setBackgroundResource(R.color.green);
        netStatusRv.setTextColor(getResources().getColor(R.color.white));
    }

    public void disConnectedNet() {
        netStatusRv.setText("未联网");
        netStatusRv.setBackgroundResource(R.color.red);
        netStatusRv.setTextColor(getResources().getColor(R.color.white));
    }
}